package com.useeinfo.oa.modules.repair.biz;

import com.useeinfo.framework.extend.biz.CrudBiz;
import com.useeinfo.framework.sugar.func.lang.StringUtils;
import com.useeinfo.framework.sugar.tools.StringConverters;
import com.useeinfo.oa.modules.base.entity.Enterprise;
import com.useeinfo.oa.modules.repair.dao.RepairOrderLogDao;
import com.useeinfo.oa.modules.repair.entity.RepairOrder;
import com.useeinfo.oa.modules.repair.entity.RepairOrderLog;
import com.useeinfo.oa.modules.repair.enums.RepairOrderLogOperationEnum;
import com.useeinfo.oa.modules.security.entity.SystemUser;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @Auther: xudong.sun
 * @Date: 2018/12/12 13:56
 * @Description:
 */
@Service("repairOrderLogBiz")
public class RepairOrderLogBiz extends CrudBiz<RepairOrderLogDao, RepairOrderLog> {

    public void addLog(RepairOrder repairOrder, SystemUser systemUser, RepairOrderLogOperationEnum repairOrderLogOperationEnum, Enterprise enterprise,String remark){
        RepairOrderLog repairOrderLog = new RepairOrderLog();
        repairOrderLog.setUserName(systemUser.getUserName());
        repairOrderLog.setCreateDate(new Date());
        repairOrderLog.setRepairOrder(repairOrder);
        repairOrderLog.setRepairOrderLogOperationEnum(repairOrderLogOperationEnum);
        repairOrderLog.setEnterprise(enterprise);
        repairOrderLog.setDetail(systemUser + " 在" + new Date() + " 对维修单 " + repairOrder.getReportCode() + " 进行了 " + repairOrderLogOperationEnum.getName() + " 操作 ");
        if(StringUtils.isNotBlank(remark)){
            repairOrderLog.setRemark(StringConverters.null2String(remark));
        }
        addOrUpdate(repairOrderLog);
    }
}
